//
//  swift5.swift
//  SwiftTest
//
//  Created by bym on 2019/8/7.
//  Copyright © 2019 ZZ. All rights reserved.
//

import UIKit

class swift5: NSObject {
//https://www.jianshu.com/p/676429df63b0
	override init() {
		super.init()
//		isMultiple()
		nativeString()
	}
}

//isMultiple(of:)
extension swift5{
	func isMultiple() {
		let a = 4
		let b = 8
		ZZLog(b.isMultiple(of: a))
	}
}

//增加了原始字符串
extension swift5{
	func nativeString() {
		//Swift 4.2 使用转义序列来表示字符串中的反斜杠和引号：
		ZZSimpleLog("swift4.2")
		let escape = "You use escape sequences for \"quotes\"\\\"backslashes\" in Swift 4.2."
		let multiline = """
                You use escape sequences for \"\"\"quotes\"\"\"\\\"\"\"backslashes\"\"\"
                on multiple lines
                in Swift 4.2.
                """
		ZZLog(escape)
		ZZLog(multiline)
		//Swift 5 增加了原始字符串，在字符串的开头和结尾添加 # 以便直接使用反斜杠和引号而不会出现问题。
		let raw = #"You can create "raw"\"plain" strings in Swift 5."#
		let multiline1 = #"""
                You can create """raw"""\"""plain""" strings
                on multiple lines
                in Swift 5.
                """#
		ZZLog(raw)
		ZZLog(multiline1)
		
		//在原始字符串中使用字符串插值时，必须在反斜杠后面使用 # 号：
		let track = "Nothing Else Matters"
		ZZLog(#"My favorite tune\song is \#(track)."#)
		track.forEach {
			//Character新增isNumberis1
			$0.isNumber
		}
		
		//通过检查每个字符的 unicode 标量是否以大写或小写字母表示来计算 username 中有多少个字母。
		//4.2
		let username = "bond007"
		var letters = 0
		username.unicodeScalars.forEach {
			letters += (65...90) ~= $0.value || (97...122) ~= $0.value ? 1 : 0
		}
		print("Username has \(letters) letters.")
		
		//5.0
		username.unicodeScalars.forEach { letters += $0.properties.isAlphabetic ? 1 : 0 }
	}
}

extension swift5{
	func sequenceRemove() {
		var sequence = [1,2,3,4,5]
		sequence.removeLast()
	}
}
